package cn.earl.springboot.entity;

import java.io.File;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;

import com.alibaba.fastjson.annotation.JSONField;

@Entity
@Table(name = "tb_demand")
public class Demand {

	@Id
	@GeneratedValue
	private int id;

	// 关联用户
	// fetch=FetchType.LAZY属性表示在多的那一方通过延迟加载的方式加载对象(默认不是延迟加载)
	@ManyToOne(targetEntity = User.class, fetch = FetchType.LAZY)
	// 通过 JoinColumn 的name属性指定了外键的名称 rid
	// (注意：如果我们不通过JoinColum来指定外键的名称，系统会给我们声明一个名称)
	// @JoinColumn(name = "user_id", insertable = false, updatable = false)
	public User user;

	// 标题
	@NotBlank
	private String title;

	// 内容
	@NotBlank
	private String content;

	// 发布时间
	@JSONField(format = Global.DATE_FORMAT)
	private Date publish_date;

	// 价格
	@Range(min = 1)
	private double price;

	// 需求的有效时间，分钟
	@Range(min = 1)
	private int effective_time;

	// 图片
	@Transient // 排除这个属性，不插入数据库
	private File picture;
	private String picture_url;

	// 状态
	private int status;

	// 联系方式
	private String contact;

	// 类型
	private DemandType demandType;

	// 用户位置

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Date getPublish_date() {
		return publish_date;
	}

	public void setPublish_date(Date publish_date) {
		this.publish_date = publish_date;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public int getEffective_time() {
		return effective_time;
	}

	public void setEffective_time(int effective_time) {
		this.effective_time = effective_time;
	}

	public File getPicture() {
		return picture;
	}

	public void setPicture(File picture) {
		this.picture = picture;
	}

	public String getPicture_url() {
		return picture_url;
	}

	public void setPicture_url(String picture_url) {
		this.picture_url = picture_url;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}

	public DemandType getDemandType() {
		return demandType;
	}

	public void setDemandType(DemandType demandType) {
		this.demandType = demandType;
	}

}
